/**
 * 将大任务拆分为单个的小任务 
 * @return {[type]} [description]
 */
 function v3() {
 	console.time("runtime");
 	let sum = 0, count = 0;
 	function hd() {
 		for (var  i = 0; i < 100000000; i++) {
 			if (num <= 0) break;
 			sum += num;
 			num --
 			count++;
 		}

 		if(num > 0) {
 			// console.log(`num = ${num}`)
 			setTimeout(hd)
 		} else {
			// 执行完成了 num =  0
			// sum = 48841639102092800, i = 87654320
			// runtime: 34989.15869140625 ms

 			console.log('执行完成了 num = ', num)
 			console.log(`sum = ${sum}, i = ${i} count= ${count}`);
 			console.timeEnd("runtime");
 		}

 	}

 	// 187654321
 	let num=187654321;
 	var s1 = 0;
 	for(var a = 0; a <= num; a++) {
 		s1 += a;
 	}

 	console.log('s1 = ', s1)
 	
 	hd(num);
	console.log("houdunren.com  多个小的宏任务"); //需要等待上面执行完才会执行
	console.log(arguments.callee.name + ' 不需要影响后面的执行')
	
}

v3()


